package com.api.mapper;

import com.api.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from user where account = #{account} and role = #{role}")
    User getByAccountRole(User user);

    @Insert("insert into user(nickname, account, password, role, gender, bid, cid, phone) value (#{nickname}, #{account}, #{password}, #{role}, #{gender}, #{bid}, #{cid}, #{phone})")
    void create(User user);

    @Update("update user set nickname = #{nickname}, gender = #{gender}, bid = #{bid}, cid = #{cid}, phone = #{phone}, state = #{state} where id = #{id}")
    void update(User user);

    @Delete("delete from user where id = #{id}")
    void remove(Integer id);

    @Select("select * from user where role = #{role} limit #{pageNo}, #{pageSize}")
    List<User> get(Integer role, Integer pageNo, Integer pageSize);

    @Select("select count(*) from user where role = #{role}")
    Integer count(Integer role);

    @Select("select * from user where role = #{role} and nickname like #{nickname} limit #{pageNo}, #{pageSize}")
    List<User> getByNickname(Integer role, Integer pageNo, Integer pageSize, String nickname);

    @Select("select count(*) from user where role = #{role} and nickname like #{nickname}")
    Integer countByNickname(Integer role, String nickname);

    @Select("select * from user where id = #{id}")
    User getById(Integer id);

    @Update("update user set password = #{password} where id = #{id}")
    void updatePassword(Integer id, String password);

    @Select("select * from user where role = #{role}")
    List<User> getAll(Integer role);

}
